package com.林子祺.CAT旅游系统.dao.placemanagement;

import com.林子祺.CAT旅游系统.entity.login.LoginStatus;
import com.林子祺.CAT旅游系统.entity.place.PlaceData;

import java.sql.*;

public class AbstractSearching {

    public static void search(String option,String content){
        java.sql.Connection conn = null;
        java.sql.PreparedStatement ps = null;
        java.sql.ResultSet rs = null;
        try {
            PlaceData.Refresh();

            conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/travelsys", "root", "@Blink102417");

            String sql = "select * from place where "+option+" like '%"+content+"%'";

            ps = conn.prepareStatement(sql);

            rs = ps.executeQuery();

            while (rs.next()) {
                PlaceData.InputData(rs.getInt("id"),rs.getString("name"),rs.getDouble("price"),rs.getString("provience"),rs.getString("city"),rs.getString("address"),rs.getString("detail"));
            }
        } catch (Exception throwables) {
            throwables.printStackTrace();
        } finally {
            if (rs != null) {
                try {
                    rs.close();
                } catch (SQLException throwables) {
                    throwables.printStackTrace();
                }
            }
            if (ps != null) {
                try {
                    ps.close();
                } catch (SQLException throwables) {
                    throwables.printStackTrace();
                }
            }
            if (conn != null) {
                try {
                    conn.close();
                } catch (SQLException throwables) {
                    throwables.printStackTrace();
                }
            }
        }
    }



}
